//
//  DengLu.m
//  Class
//
//  Created by 钟纪旺 on 17/3/14.
//  Copyright © 2017年 zjw. All rights reserved.
//

#import "DengLu.h"
#import "NetWorkingHandle.h"
#import "MJExtension.h"
#import "CustomModel.h"

@interface DengLu ()

@property (weak, nonatomic) IBOutlet UITextField *usedName;
@property (weak, nonatomic) IBOutlet UITextField *passWord;

@end

@implementation DengLu

- (void)showMessage:(NSString *)message
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示消息" message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
    
    [alertVC addAction:ok];
    
    [self presentViewController:alertVC animated:YES completion:nil];
}
- (IBAction)onDengLu:(id)sender {
    if (!_usedName.text.length) {
        [self showMessage:@"请输入用户名"];
        return;
    }
    
    if (!_passWord.text.length) {
        [self showMessage:@"请输入密码"];
        return;
    }

    NSDictionary *param = @{@"name":self.usedName.text,@"password":self.passWord.text};
    [NetWorkingHandle requestDataWithURL:@"login" withParams:param withRequestType:GET succeccBlock:^(NSDictionary *dic) {
        
        
        if ([dic[@"errcode"] intValue] == 0) {
          dispatch_sync(dispatch_get_main_queue(), ^{
              UITabBarController *myView =[self.storyboard instantiateViewControllerWithIdentifier:@"liudehua"];
               //推进去
            [self presentViewController:myView animated:YES completion:^{
                
            }];
          });
           
        }else{
            NSLog(@"登录失败");
        
        }
        
    } failedBlock:^(NSError *error) {
        
    }];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
